package com.woniu.microassetserver.controller;


import com.github.pagehelper.PageInfo;
import com.woniu.microassetserver.service.DevSystemService;
import com.woniu.microcommonsserver.entity.DevSystemEntity;
import com.woniu.microcommonsserver.entity.ResultMsg;
import com.woniu.microcommonsserver.param.PageResult;
import com.woniu.microcommonsserver.param.ResponseMsg;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


/**
 * 
 *
 * @author luoyue
 * @email 1316756109@qq.com
 * @date 2021-01-29
 */
@RestController
@RequestMapping("/devsystem")
public class DevSystemController {


    @Resource
    private DevSystemService devSystemServiceImpl;


    @RequestMapping(value = "/more", produces = {"application/json;charset=utf-8"})
    public ResultMsg saveDevSystem() {

        System.out.println("添加");
        ResultMsg resultMsg = new ResultMsg(200, "新增成功", null);
        DevSystemEntity devSystemEntity = new DevSystemEntity(3L, "对讲系统", "T9", "通话", 1L, "附件qwr", "负责人名字", "15508063557", "总经理");
        devSystemServiceImpl.saveDevSystem(devSystemEntity);
        System.out.println(devSystemEntity);
        System.out.println("新增成功");
        return resultMsg;
    }


    @PutMapping(value = "/id/{id}", produces = {"application/json;charset=utf-8"}) /*AssetsParameterBean assetsParameterBean, @PathVariable("id") Long id*/
    public ResultMsg updateDevSystem(@PathVariable("id") Long id) {
        ResultMsg resultMsg = new ResultMsg(200, "更新成功", null);
        System.out.println(id);
        DevSystemEntity devSystemEntity = new DevSystemEntity(3L, "排水系统", "T9", "通话", 1L, "附件qwr", "负责人名字", "15508063557", "总经理");
        devSystemServiceImpl.updateDevSystem(devSystemEntity);
        return resultMsg;
    }


    @DeleteMapping(value = "/delete/{id}", produces = {"application/json;charset=utf-8"})
    public ResultMsg deleteDevSystem(@PathVariable("id") Long id) {

        System.out.println("添加");

        ResultMsg resultMsg = new ResultMsg(200, "删除成功", null);

        devSystemServiceImpl.deleteDevSystem(id);

        System.out.println("删除成功");

        return  resultMsg;

    }

    @GetMapping(value = "/selectAll", produces = {"application/json;charset=utf-8"})
    public ResponseMsg selectDevSystem(Integer pageNum, Integer pageSize, DevSystemEntity devSystemEntity) {

        System.out.println("哦呵呵查询");




        PageInfo<DevSystemEntity> pageInfo =devSystemServiceImpl.findAllByParams(pageNum, pageSize, devSystemEntity);

        PageResult<DevSystemEntity> pageResult=new PageResult<DevSystemEntity>();
        pageResult.setRows(pageInfo.getList());
        pageResult.setTotal(pageInfo.getTotal());

        return ResponseMsg.builder().code(200).msg("查询陈工").data(pageResult).build();

    }

    @GetMapping(value = "/getOneById", produces = {"application/json;charset=utf-8"})
        public ResultMsg getOneById(Long id) {
        System.out.println("添加");

        ResultMsg resultMsg = new ResultMsg(200, "查询成功", null);
        DevSystemEntity devSystemEntity = devSystemServiceImpl.getOneById(id);
        resultMsg.setData(devSystemEntity);
        return  resultMsg;

    }
}

